package com.cy.study.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cy.study.common.Response;
import com.cy.study.req.AddPushReq;
import com.cy.study.req.HandlePushPlanReq;
import com.cy.study.req.PushPageReq;
import com.cy.study.res.PushDetailRes;
import com.cy.study.res.PushGetNewsRes;
import com.cy.study.res.PushPageRes;
import com.cy.study.service.NewsService;
import com.cy.study.service.PushRecordService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 推送控制器
 */
@RequiredArgsConstructor
@RequestMapping("/push")
@RestController
@CrossOrigin
@Slf4j
public class PushController {

    private final PushRecordService pushRecordService;
    private final NewsService newsService;

    /**
     * 管理端推送列表
     * @param req
     * @return
     */
    @PostMapping("/page")
    public Response<Page<PushPageRes>> pagePush(@RequestBody PushPageReq req){
        Page<PushPageRes> res = pushRecordService.pagePush(req);
        return Response.success(res);
    }


    /**
     * 管理端推送详情
     * @param pushRecordId
     * @return
     */
    @GetMapping("/detail/{pushRecordId}")
    public Response<PushDetailRes> detail(@PathVariable Integer pushRecordId){
        PushDetailRes res = pushRecordService.detail(pushRecordId);
        return Response.success(res);
    }


    /**
     * 获取一个月内资讯
     */
    @GetMapping("/pushGetNews")
    public Response<List<PushGetNewsRes>> pushGetNews(){
        List<PushGetNewsRes> res = newsService.pushGetNews();
        return Response.success(res);
    }

    /**
     * 手动推送
     * @param req
     * @return
     */
    @PostMapping("/handlePushPlan")
    public Response handlePushPlan(@RequestBody HandlePushPlanReq req){
        pushRecordService.handlePushPlan(req);
        return Response.success();
    }

}
